package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.dto.sys.SysRoleDto;
import com.atguigu.spzx.model.entity.sys.SysRole;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2023/12/27
 * description：
 */
@RestController
@RequestMapping("/admin/system/role")
@Tag(name = "角色管理模块")
//@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true", allowedHeaders = {"*"})
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    //角色分类查询带分页
    @PostMapping("/getRole")
    @Operation(summary = "角色查询接口")
    public Result getRole(@RequestBody SysRoleDto sysRoleDto) {
        PageInfo<SysRole> pageInfo = sysRoleService.getRoleList(sysRoleDto);
        return Result.ok(pageInfo);
    }

    //删除角色
    @DeleteMapping("deleteRole/{id}")
    @Operation(summary = "删除角色接口")
    public Result deleteById(@PathVariable Long id) {
        //可能会删除数据的id
        sysRoleService.deleteById(id);
        return Result.ok();
    }

    //添加角色
    @PostMapping("/saveRole")
    @Operation(summary = "添加角色接口")
    public Result save(@RequestBody SysRole sysRole) {
        sysRoleService.save(sysRole);
        return Result.ok();
    }

    //修改角色
    @PutMapping("/updateRole")
    @Operation(summary = "修改角色接口")
    public Result updateRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateRole(sysRole);
        return Result.ok();
    }
}
